<?php
/**
 * 精彩瞬间
 * User: Administrator
 * Date: 2022/3/19
 * Time: 16:08
 */

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Request;

class WonderfulMoment extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function list()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $limit = input('get.limit',10);
        $page = input('get.page',1);

        $list = Db::name('wonderful_moment')->field('id,title,cover')->order('id','desc')->paginate($limit,false,['page'=>$page]);
        if(!$list)
            $this->error('暂无数据');
        /*$list = $list->toArray();

        foreach($list['data'] as $k=>&$v)
        {
            if($v['images'])
            {
                $v['images'] = explode(',',$v['images']);
            }
        }*/
        $this->success('',$list);

    }

    public function detail()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        if(!$id = input('get.id'))
            $this->error('缺少参数');

        $info = Db::name('wonderful_moment')->where('id',$id)->find();
        if(!$info)
            $this->error('暂无数据');
        if($info['images'])
        {
            $info['images'] = explode(',',$info['images']);
        }

        $this->success('',$info);
    }
}